﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using OxyPlot;

namespace PlayOxyPlot
{
    public partial class LineAndAreaView : UserControl
    {
        public LineAndAreaView()
        {
            InitializeComponent();

            var model = new PlotModel("Title: LineSeries and AreaSeries");

            SetAxis(model);

            const double start = 1;
            const double end = 10;
            const double step = 0.1;
            AddArea(model, start, end, step);
            AddLine(model, start,end,step);

            plot.Model = model;
        }

        private static void SetAxis(PlotModel model)
        {
            var xAxis = new LinearAxis(AxisPosition.Bottom, "X");
            model.Axes.Add(xAxis);

            var yAxis = new LinearAxis(AxisPosition.Left, "Y");
            model.Axes.Add(yAxis);
        }

        private static void AddLine(PlotModel model, double start, double end, double step)
        {
            var lineseries = new LineSeries
                                 {
                                     Color = OxyColors.Blue,
                                     Title = "Line",
                                 };
            for (double x = start; x < end; x += step)
            {
                lineseries.Points.Add(new DataPoint(x, Math.Sin(x)));
            }//for
            model.Series.Add(lineseries);
        }

        private static void AddArea(PlotModel model, double start, double end, double step)
        {
            var areaseries = new AreaSeries
                                 {
                                     Fill = OxyColors.Orange,
                                     Color = OxyColors.Red,
                                     MarkerFill = OxyColors.Transparent,
                                 };
            for (double x = start; x < end; x += step)
            {
                double y1 = Math.Cos(x);
                double y2 = 0.5 + y1;
                areaseries.Points.Add(new DataPoint(x, y1));
                areaseries.Points2.Add(new DataPoint(x, y2));
            }
            model.Series.Add(areaseries);
        }
    }//LineAndAreaView
}
